//
//  RankViewController.m
//  海角音乐
//
//  Created by dllo on 15/8/14.
//  Copyright (c) 2015年 杨元石. All rights reserved.
//

#import "RankViewController.h"

@interface RankViewController ()

@end

@implementation RankViewController

- (void)viewWillAppear:(BOOL)animated
{
    BarPlayer = [DanLiPlayer shareHandleDanLiPlayer:CGRectZero];
    
    [self.view addSubview:BarPlayer];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    
    CGFloat title_width = SCREEN_WIDTH*0.533333; // 200
    CGFloat title_height = SCREEN_WIDTH*0.08; // 30
    self.TitleView = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, title_width, title_height)];
    self.TitleView.textColor = [UIColor whiteColor];
    self.TitleView.textAlignment = NSTextAlignmentCenter;
    self.TitleView.text = @"排行";
    self.navigationItem.titleView = self.TitleView;
    
    
    _RankModelArr = [[NSMutableArray alloc] init];
    _RankView = [[RankView alloc] initWithFrame:CGRectMake(0, 64, SCREEN_WIDTH, SCREEN_HEIGHT)];
    _RankView.tableView.dataSource = self;
    _RankView.tableView.delegate = self;
    _RankView.tableView.separatorColor = [UIColor clearColor];
    _RankView.tableView.backgroundColor = [UIColor clearColor];
    [self.view addSubview:_RankView];
    [_RankView release];
    
    
    HUD = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
    HUD.removeFromSuperViewOnHide = YES;
    HUD.labelText = @"loading...";
    [self.view addSubview:HUD];
    HUD.mode = MBProgressHUDModeIndeterminate;
    
    [self getDataForMusic];
    
    
    
    // Do any additional setup after loading the view.
}


- (void)getDataForMusic
{
    [HttpResponse urlString:RankMusicUrl getResponseObject:^(id responseObject) {
        NSArray *dataArr = [responseObject objectForKey:@"data"];
        for (NSDictionary *dic in dataArr) {
            RankModel *rankModel = [[RankModel alloc] init];
            [rankModel setValuesForKeysWithDictionary:dic];
            [_RankModelArr addObject:rankModel];
        }
        [HUD removeFromSuperview];
        [_RankView.tableView reloadData];
    }];
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return _RankModelArr.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    static NSString *cellId = @"cell";
    RankTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellId];
    if (cell == NO) {
        cell = [[RankTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellId];
    }
    RankModel *rankModel = [_RankModelArr objectAtIndex:indexPath.row];
    [cell getDataModel:rankModel];
    return cell;
}


- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    return 125*ADJUSTWIDTH;
}


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    RankDetailViewController  *rankVc = [[[RankDetailViewController alloc] init] autorelease];
    RankModel *rankModel = [_RankModelArr objectAtIndex:indexPath.row];
    rankVc.rankModel = rankModel;
    [self.navigationController pushViewController:rankVc animated:YES];
}




- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
